home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / Fresco / build / Unix / config / util / ldso < prev    next >
Encoding:
Text File  |  1995-07-12  |  1.5 KB  |  67 lines

  1. #!/bin/sh
  2. #
  3. # ldso 
  4. # build a .so for C++ modules 
  5. # these may contain *__link structs which contain
  6. # constructors and destructors, these are packaged 
  7. # in an added module, under a routine called _init()
  8. # then this module is compiled and included in the ".so" 
  9. # rtld() will, at runtime load the ".so" and call any _init() 
  10. # routines in the .so, so we will get our constructors called.
  11. #
  12. # hess@sco.com 4/20/95
  13. args=$*
  14. prog=$0
  15. fail=1
  16. CC=cc
  17. CFLAGS=-belf
  18. INITFILE=_soinit.c
  19. INITOBJ=_soinit.o
  20. init=""
  21. needs_init=0
  22. LD=ld
  23.  
  24. Bail() { 
  25.     echo "error: $prog: $1"
  26.     exit $fail
  27. has__link() { 
  28.     [ -f $1 ] || Bail "Can't open $1"
  29.     nm -p $1 |grep  __link >/dev/null
  30.     return $?
  31.  
  32. # loop thru the objects to see if we need to build an  
  33. # init module 
  34. for i in $args;  do     case $i in 
  35.     *.o)    if has__link $i 
  36.         then     needs_init=1; break; fi
  37.     ;;
  38. esac; done
  39.  
  40. [ $needs_init -eq 1 ] && { 
  41.     # _init module is needed, set the var "init" to the object name
  42.     echo "struct __linkl { struct __linkl * next;" > $INITFILE
  43.     echo "void (*ctor)(); void (*dtor)(); };" >> $INITFILE
  44.     echo "void _init() {  "                 >> $INITFILE
  45.     for i in $args; do case $i in
  46.         *.o)  
  47.             echo    // links from $i
  48.             nm -p $i |grep __link |\
  49.              awk '{
  50.             printf("{ extern struct __linkl %s;\n (*(%s.ctor))(); }\n",$3,$3); 
  51.              }'
  52.         ;;
  53.     esac; done >> $INITFILE
  54.     echo "}  "                 >> $INITFILE
  55.     ## compile the init file
  56.     $ECHO $CC $CFLAGS -c $INITFILE
  57.     init=$INITOBJ
  58.     [ -f $init ] || Bail "can't build $init"
  59.  
  60. # do the link
  61. $ECHO $LD $init $args 
  62. exit $?
  63.